********* Table A18 *********
clear all
set more off 
capture log close
 
* main path to data
global path "~/Dropbox/Paraguay/1_data/7_replication_dataverse"
capture cd "$path"	

*tables = analysis tables
global tables "$path/tables"

* load rural collective action data
use "$path/data/landinv.dta", clear

xtset district_code year

// Generate indicator variables for years 
forval year = 1954/2007 {
    generate y`year' = (year == `year')
}

// Generate the alt_1989 variable and set it to 0
generate alt_1988 = 0

set matsize 10000
* count number of observations in the sample
count if inrange(year, 1983, 1995)
local obs_shown = r(N)

reg l_linv   c.lambda_z ///
                         y1954#c.lambda_z ///
                         y1955#c.lambda_z y1956#c.lambda_z y1957#c.lambda_z y1958#c.lambda_z ///
                         y1959#c.lambda_z y1960#c.lambda_z y1961#c.lambda_z y1962#c.lambda_z ///
                         y1963#c.lambda_z y1964#c.lambda_z y1965#c.lambda_z y1966#c.lambda_z ///
                         y1967#c.lambda_z y1968#c.lambda_z y1969#c.lambda_z y1970#c.lambda_z ///
                         y1971#c.lambda_z y1972#c.lambda_z y1973#c.lambda_z y1974#c.lambda_z ///
                         y1975#c.lambda_z y1976#c.lambda_z y1977#c.lambda_z y1978#c.lambda_z ///
                         y1979#c.lambda_z y1980#c.lambda_z y1981#c.lambda_z y1982#c.lambda_z ///
                         y1983#c.lambda_z y1984#c.lambda_z y1985#c.lambda_z y1986#c.lambda_z ///
                         y1987#c.lambda_z alt_1988 y1989#c.lambda_z y1990#c.lambda_z ///
                         y1991#c.lambda_z y1992#c.lambda_z y1993#c.lambda_z y1994#c.lambda_z ///
                         y1995#c.lambda_z y1996#c.lambda_z  y1997#c.lambda_z y1998#c.lambda_z ///
                         y1999#c.lambda_z y2000#c.lambda_z  y2001#c.lambda_z y2002#c.lambda_z ///
                         y2003#c.lambda_z y2004#c.lambda_z  y2005#c.lambda_z y2006#c.lambda_z ///
                         y2007#c.lambda_z ///
                         i.year i.district_code i.year##i.depa,  cluster(district_code)
eststo
estadd scalar obs_shown = `obs_shown'
						 
reg linv_b   c.lambda_z ///
                         y1954#c.lambda_z ///
                         y1955#c.lambda_z y1956#c.lambda_z y1957#c.lambda_z y1958#c.lambda_z ///
                         y1959#c.lambda_z y1960#c.lambda_z y1961#c.lambda_z y1962#c.lambda_z ///
                         y1963#c.lambda_z y1964#c.lambda_z y1965#c.lambda_z y1966#c.lambda_z ///
                         y1967#c.lambda_z y1968#c.lambda_z y1969#c.lambda_z y1970#c.lambda_z ///
                         y1971#c.lambda_z y1972#c.lambda_z y1973#c.lambda_z y1974#c.lambda_z ///
                         y1975#c.lambda_z y1976#c.lambda_z y1977#c.lambda_z y1978#c.lambda_z ///
                         y1979#c.lambda_z y1980#c.lambda_z y1981#c.lambda_z y1982#c.lambda_z ///
                         y1983#c.lambda_z y1984#c.lambda_z y1985#c.lambda_z y1986#c.lambda_z ///
                         y1987#c.lambda_z alt_1988 y1989#c.lambda_z y1990#c.lambda_z ///
                         y1991#c.lambda_z y1992#c.lambda_z y1993#c.lambda_z y1994#c.lambda_z ///
                         y1995#c.lambda_z y1996#c.lambda_z  y1997#c.lambda_z y1998#c.lambda_z ///
                         y1999#c.lambda_z y2000#c.lambda_z  y2001#c.lambda_z y2002#c.lambda_z ///
                         y2003#c.lambda_z y2004#c.lambda_z  y2005#c.lambda_z y2006#c.lambda_z ///
                         y2007#c.lambda_z ///
                         i.year i.district_code i.year##i.depa,  cluster(district_code)
						 
eststo
estadd scalar obs_shown = `obs_shown'

						 
reg l_peasfam   c.lambda_z ///
                         y1954#c.lambda_z ///
                         y1955#c.lambda_z y1956#c.lambda_z y1957#c.lambda_z y1958#c.lambda_z ///
                         y1959#c.lambda_z y1960#c.lambda_z y1961#c.lambda_z y1962#c.lambda_z ///
                         y1963#c.lambda_z y1964#c.lambda_z y1965#c.lambda_z y1966#c.lambda_z ///
                         y1967#c.lambda_z y1968#c.lambda_z y1969#c.lambda_z y1970#c.lambda_z ///
                         y1971#c.lambda_z y1972#c.lambda_z y1973#c.lambda_z y1974#c.lambda_z ///
                         y1975#c.lambda_z y1976#c.lambda_z y1977#c.lambda_z y1978#c.lambda_z ///
                         y1979#c.lambda_z y1980#c.lambda_z y1981#c.lambda_z y1982#c.lambda_z ///
                         y1983#c.lambda_z y1984#c.lambda_z y1985#c.lambda_z y1986#c.lambda_z ///
                         y1987#c.lambda_z alt_1988 y1989#c.lambda_z y1990#c.lambda_z ///
                         y1991#c.lambda_z y1992#c.lambda_z y1993#c.lambda_z y1994#c.lambda_z ///
                         y1995#c.lambda_z y1996#c.lambda_z  y1997#c.lambda_z y1998#c.lambda_z ///
                         y1999#c.lambda_z y2000#c.lambda_z  y2001#c.lambda_z y2002#c.lambda_z ///
                         y2003#c.lambda_z y2004#c.lambda_z  y2005#c.lambda_z y2006#c.lambda_z ///
                         y2007#c.lambda_z ///
                         i.year i.district_code i.year##i.depa,  cluster(district_code)

eststo
estadd scalar obs_shown = `obs_shown'
						 
reg l_hectares  c.lambda_z ///
                         y1954#c.lambda_z ///
                         y1955#c.lambda_z y1956#c.lambda_z y1957#c.lambda_z y1958#c.lambda_z ///
                         y1959#c.lambda_z y1960#c.lambda_z y1961#c.lambda_z y1962#c.lambda_z ///
                         y1963#c.lambda_z y1964#c.lambda_z y1965#c.lambda_z y1966#c.lambda_z ///
                         y1967#c.lambda_z y1968#c.lambda_z y1969#c.lambda_z y1970#c.lambda_z ///
                         y1971#c.lambda_z y1972#c.lambda_z y1973#c.lambda_z y1974#c.lambda_z ///
                         y1975#c.lambda_z y1976#c.lambda_z y1977#c.lambda_z y1978#c.lambda_z ///
                         y1979#c.lambda_z y1980#c.lambda_z y1981#c.lambda_z y1982#c.lambda_z ///
                         y1983#c.lambda_z y1984#c.lambda_z y1985#c.lambda_z y1986#c.lambda_z ///
                         y1987#c.lambda_z alt_1988 y1989#c.lambda_z y1990#c.lambda_z ///
                         y1991#c.lambda_z y1992#c.lambda_z y1993#c.lambda_z y1994#c.lambda_z ///
                         y1995#c.lambda_z y1996#c.lambda_z  y1997#c.lambda_z y1998#c.lambda_z ///
                         y1999#c.lambda_z y2000#c.lambda_z  y2001#c.lambda_z y2002#c.lambda_z ///
                         y2003#c.lambda_z y2004#c.lambda_z  y2005#c.lambda_z y2006#c.lambda_z ///
                         y2007#c.lambda_z ///
                         i.year i.district_code i.year##i.depa,  cluster(district_code)
						 
eststo
estadd scalar obs_shown = `obs_shown'
					 

capture cd "$tables"
esttab est* using "tableA18.tex", replace nonumber label style(tex) ///
        cells(b(star fmt(%12.4fc)) se(par fmt(%12.4fc))) ///
        stats( obs_shown r2 , fmt( %12.0fc %12.4fc ) ///
            label("\hline Observations (1983-1995)"  ///
              "\$R^2\$" )) ///
        keep( 1.y1983#c.lambda_z 1.y1984#c.lambda_z 1.y1985#c.lambda_z ///
        1.y1986#c.lambda_z 1.y1987#c.lambda_z 1.y1989#c.lambda_z 1.y1990#c.lambda_z ///
        1.y1991#c.lambda_z 1.y1992#c.lambda_z 1.y1993#c.lambda_z 1.y1994#c.lambda_z 1.y1995#c.lambda_z ) ///    
        order(1.y1983#c.lambda_z 1.y1984#c.lambda_z 1.y1985#c.lambda_z ///
        1.y1986#c.lambda_z 1.y1987#c.lambda_z  1.y1989#c.lambda_z 1.y1990#c.lambda_z ///
        1.y1991#c.lambda_z 1.y1992#c.lambda_z 1.y1993#c.lambda_z 1.y1994#c.lambda_z 1.y1995#c.lambda_z ) ///
        varlabels(1.y1983#c.lambda_z "Year 1983 \$\times\$ Largest Eigenvalue" 1.y1984#c.lambda_z "Year 1984 \$\times\$ Largest Eigenvalue" ///
        1.y1985#c.lambda_z "Year 1985 \$\times\$ Largest Eigenvalue" ///
        1.y1986#c.lambda_z "Year 1986 \$\times\$ Largest Eigenvalue" 1.y1987#c.lambda_z "Year 1987 \$\times\$ Largest Eigenvalue" ///
        1.y1989#c.lambda_z "Year 1989 \$\times\$ Largest Eigenvalue" 1.y1990#c.lambda_z "Year 1990 \$\times\$ Largest Eigenvalue" ///
        1.y1991#c.lambda_z "Year 1991 \$\times\$ Largest Eigenvalue" 1.y1992#c.lambda_z "Year 1992 \$\times\$ Largest Eigenvalue" ///
        1.y1993#c.lambda_z "Year 1993 \$\times\$ Largest Eigenvalue" 1.y1994#c.lambda_z "Year 1994 \$\times\$ Largest Eigenvalue" ///
        1.y1995#c.lambda_z "Year 1995 \$\times\$ Largest Eigenvalue") ///    
        collabels(, none) eqlabels(, none) starlevels(* 0.1 ** 0.05 *** 0.01) ///
        prehead(\begin{tabular}{l*{@M}{c}} \hline ///
            &  \multicolumn{1}{c}{Land Occupations (log)} &  \multicolumn{1}{c}{Land Occupations (binary)}   &  \multicolumn{1}{c}{Squatter Peasants (log)}  ///
            &  \multicolumn{1}{c}{Occupied Hectares (log)}  \\ ///
            & (1)  & (2) & (3) & (4)              \\)  ///
        posthead(\hline ) mlabels(, none) ///
        prefoot( ) postfoot(\hline \end{tabular})
		
